<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAfterServicesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('after_services', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned()->index();
            $table->integer('device_id')->unsigned()->index();
            //设备故障
            $table->string('equipment_failure');
            //故障描述
            $table->text('failure_description');
            //上门服务
            $table->boolean('door_to_door_service')->default(0);
            $table->string('name');
            $table->string('phone');
            $table->string('installation_address');
            $table->boolean('status')->default(0);
            $table->timestamps();

            $table->foreign('user_id')
                  ->references('id')
                  ->on('users')
                  ->onDelete('cascade')
                  ->onUpdate('cascade');

            $table->foreign('device_id')
                  ->references('id')
                  ->on('devices')
                  ->onDelete('cascade')
                  ->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('after_services');
    }
}
